<template>
<div>
  <van-address-list
    v-model="chosenAddressId"
    :list="list"
    :disabled-list="disabledList"
    disabled-text="以下地址超出配送范围"
    default-tag-text="默认"
    @add="onAdd"
    @edit="onEdit"
  />
</div>
</template>

<script>
import { getAddressList } from '@/api/address'

export default {
  name: 'addressIndex',
  data () {
    return {
      chosenAddressId: '',
      list: [],
      disabledList: []
    }
  },
  methods: {
    onAdd () {
      this.$router.push('/editAddress')
    },
    onEdit (item, index) {
      this.$router.push(`/editAddress/${item.id}`)
    },
    async getAddressList () {
      const { data: { list } } = await getAddressList()
      this.chosenAddressId = this.$route.params.id
      console.log(list)
      this.list = list.map(item => {
        return { id: item.address_id, name: item.name, tel: item.phone, address: item.region.province + item.region.city + item.region.region + item.detail }
      })
      this.list[0].isDefault = true
    }
  },
  created () {
    this.getAddressList()
  }
}
</script>

<style scoped>

</style>
